package top.minuy.structure.stack;
/**
 * @author Minuy
 * @time 11:54
 * @date 2021/8/22
 */
public class Test {

    static double testStack(Stack<Integer> stack, int opCount){
        boolean check = true;
        long startTime = System.nanoTime();

        int i=0;
        for (;i<opCount;i++){
            stack.push(i);
        }

        i--;
        int tag;
        for (;i>0;i--){
            tag = stack.pop();
            if(tag!=i){
                check = false;
            }
        }

        long endTime = System.nanoTime();

        System.out.println("check = "+check+", time = "+(endTime-startTime)/1000000000.0+" s");

        return (endTime-startTime)/1000000000.0;
    }

    static double testStack(int opCount){
        java.util.Stack<Integer> stack = new java.util.Stack<>();
        boolean check = true;
        long startTime = System.nanoTime();

        int i=0;
        for (;i<opCount;i++){
            stack.push(i);
        }

        i--;
        int tag;
        for (;i>0;i--){
            tag = stack.pop();
            if(tag!=i){
                check = false;
            }
        }

        long endTime = System.nanoTime();

        System.out.println("check = "+check+", time = "+(endTime-startTime)/1000000000.0+" s");

        return (endTime-startTime)/1000000000.0;
    }

    public static void main(String[] args) {
        ArrayStack<Integer> stack = new ArrayStack<Integer>();

        for (int i=0;i<11;i++){
            stack.push(i+1);
            System.out.println(stack.toString());
        }

        for (int i=4;i>0;i--) {
            stack.pop();
            System.out.println(stack.toString());
        }

        System.out.println("--------------LinkedListStack------------------");

        LinkedListStack<Integer> linkedListStack = new LinkedListStack<Integer>();

        for (int i=0;i<11;i++){
            linkedListStack.push(i+1);
            System.out.println(linkedListStack.toString());
        }

        for (int i=4;i>0;i--) {
            linkedListStack.pop();
            System.out.println(linkedListStack.toString());
        }

        System.out.println();
        int opCount = 100000;
        System.out.println("性能测试：");
        System.out.println();
        System.out.println("------> opCount = "+opCount);

        System.out.println("Array Stack : ");
        testStack(new ArrayStack<Integer>(),opCount);
        System.out.println("Linked List Stack : ");
        testStack(new LinkedListStack<Integer>(),opCount);
        System.out.println("System Stack : ");
        testStack(opCount);

        opCount*=100;
        System.out.println();
        System.out.println("------> opCount = "+opCount);

        System.out.println("Array Stack : ");
        testStack(new ArrayStack<Integer>(),opCount);
        System.out.println("Linked List Stack : ");
        testStack(new LinkedListStack<Integer>(),opCount);
        System.out.println("System Stack : ");
        testStack(opCount);
    }
}
